package com.indra.archetypeweb.dao.user;

import java.util.List;

import javax.persistence.PersistenceException;

import org.springframework.stereotype.Repository;

import com.indra.archetypeweb.dao.base.BaseDaoImpl;
import com.indra.archetypeweb.entity.user.User;

@Repository
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.indra.archetypeweb.domain.UserDao#findByUsername(java.lang.String)
	 */
	@Override
	public User findByUsername(String username) {
		try {
			return em.createNamedQuery(User.FIND_BY_USERNAME, User.class)
					.setParameter("username", username).getSingleResult();
		} catch (PersistenceException e) {
			return null;
		}
	}

	@Override
	public List<User> findAll() {

		return em.createNamedQuery(User.FIND_ALL, User.class).getResultList();

	}

}
